package com.example.spring.thread.create;

import java.util.Scanner;
import java.util.concurrent.*;

/**
 * @author: orange
 * @create: 2023-08-04 21:23
 * @description:
 */
public class ExecutorServiceMain {

    public static ExecutorService executorService(BlockingQueue<Runnable> queue) {
        return new ThreadPoolExecutor(1, 10, 60L, TimeUnit.SECONDS, queue);
    }

    public static void main(String[] args) {
        BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(11);
        ExecutorService executorService = executorService(blockingQueue);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            if ("queue".equals(scanner.nextLine())) {
                executorService.submit(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println("消费");
                    }
                });
            }
        }
    }
}
